package CamEndzyx;

import java.awt.*;

public class MyShape {
    public int x1,x2,y1,y2;
    public String name="";
    public Color color;

    public void drawShape(Graphics g) {
        System.out.println("name = "+name);
        switch(name) {

            case"直线":
                g.setColor(color);
                g.drawLine(x1,y1,x2,y2);
                break;

            case"矩形":
                g.setColor(color);
                g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2-x1), Math.abs(y2-y1));
                break;

            case"椭圆":
                g.setColor(color);
                g.drawOval(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2-x1), Math.abs(y2-y1));
                break;

            case"三角形":
                g.setColor(color);
                int[]xPoints1=new int[] {x1,(x1+x2)/2,x2};
                int[]yPoints1=new int[] {y2,y1,y2};
                int nPoints1=3;
                g.drawPolygon(xPoints1,yPoints1,nPoints1);
                break;

            case"正方形":
                g.setColor(color);
                g.drawRect(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2-x1), Math.abs(x2-x1));
                break;

            case"菱形":
                g.setColor(color);
                int[]xPoints2=new int[] {(x1+x2)/2,x2,(x1+x2)/2,x1};
                int[]yPoints2=new int[] {y2,(y1+y2)/2,y1,(y1+y2)/2};
                int nPoints2=4;
                g.drawPolygon(xPoints2, yPoints2, nPoints2);
                break;

            case"特殊三角形":
                g.setColor(color);
                g.drawLine(x1,y1,x2,y2);
                break;

            case"多边形":
                g.setColor(color);
                g.drawLine(x1,y1,x2,y2);
                break;
        }
    }
}
